package com.cat.dataStructure02;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-number-of-swaps-to-make-the-string-balanced/
 * @create 2025/10/26 15:58
 * @since JDK17
 */

public class Solution61 {
    public int minSwaps(String s) {
        int ans = 0, c = 0;
        for (char x : s.toCharArray()) {
            if (x == '[') {
                c++;
            } else if (c > 0) {
                c--;
            } else {
                ans++;
                c++;    // 此时的右括号被换成了左括号
            }
        }

        return ans;
    }
}
